#!/bin/sh
#
# sniff_to_softbench
#
# Convert SNiFF+ action notifications to SoftBench requests.
#
# This script registers with SNiFF+ for `file changed' notifications
# and sends a `FILE-MODIFIED' message via the program `ciclient' to SoftBench.
#

PROG=`basename $0`

if [ $# = 0 ]; then

  # Register self with SNiFF+ for all `file changed' notifications.
  # This means this script is invoked again when a notification from
  # SNiFF+ is received, but this time with arguments (see else branch below).

  ( echo register '*/' file_changed  post nowait $0 ; \
    echo register '*/' checkout_file post nowait $0 ; \
    echo register '*/' checkin_file  post nowait $0 ; \
    echo register '*/' lock_file     post nowait $0 ; \
    echo register '*/' unlock_file   post nowait $0 ) \
  | sniffaccess

else	# Script has been invoked with arguments
	# Arguments are: {"PRE"|"POST"} {"WAIT"|"NOWAIT"} ACTION [ARG ...]

  PRE_POST=$1; shift
  WHEN=$1; shift
  ACTION=$1; shift
  ARGS="$@"

  case "$ACTION" in

    file_changed | checkout_file | checkin_file | lock_file | unlock_file)
      # $1 is PROJECT, $2 is PATHNAME
      DIR=`dirname $2`
      FILE=`basename $2`
      echo send_notify FILE-MODIFIED $FILE NULL PASS NULL | \
	ciclient -directory $DIR
    ;;

    *)
      echo $PROG: cannot convert action $ACTION
    ;;

  esac

fi

exit 0
